export default {
    namespaced: true,
    state: {
        token: '', //用户token
        menuCollapse: false, //菜单是否卷缩
        showHeaderMenu: true, //顶部是否显示菜单
        userInfo: undefined, //用户信息
        menuList: [],  //菜单列表
        routeList: undefined,  //动态路由
        dictItems:[], //系统菜单
    },
    mutations: {
        token(state: any, value: any) {state.token = value;},
        menuCollapse(state: any, value: any) {state.menuCollapse = value;},
        showHeaderMenu(state: any, value: any) {state.showHeaderMenu = value;},
        userInfo(state: any, value: any) {state.userInfo = value;},
        menuList(state: any, value: any) {state.menuList = value;},
        routeList(state: any, value: any) {state.routeList = value;},
        dictItems(state: any, value: any) {state.dictItems = value;},

        //清空所有缓存
        cleanAll(state: any, value: any) {
            let names = Object.getOwnPropertyNames(state);
            for (const name of names) {
                if (Array.isArray(state[name])) {
                    state[name] = [];
                } else {
                    state[name] = undefined;
                }
            }
        },
    },
    actions: {},
    modules: {},
    getters: {
        showHeaderMenu: (state:any) => () => {
            if (state.showHeaderMenu == undefined) {
                state.showHeaderMenu = true;
            }
            return state.showHeaderMenu;
        }
    }
}